clear*
set maxvar 11000

global date _2025_10_28
cd "/Users/atri0032/Dropbox/World Bank/Temperature, poverty, and inequality/Estimations/"

***************************************************************************************************************************************************************
********************************** Table S15: The effects of temperature on poverty and inequality for higher poverty lines and Theil index, by income group
***************************************************************************************************************************************************************

//==========================//	

* FE model 
use "${date}/_data/spid_for_analysis_v2.dta", clear

	sort code year
	merge m:1 code year using "${date}/_data/income_classification.dta"
	drop if _merge==2
	drop _merge

* Income classification based on 1st data point
bysort code (year): gen income_classification_1st = income_classification[1]
	replace income_classification_1st = "" if income_classification==""
	
estimates clear	
	
local controls ln_GDPppp Unempilo agri manuf popgr 
	
reghdfe poor365 temp rainfall_sum humid `controls' if inlist(income_classification_1st,"L","LM"), absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m1
reghdfe poor365 temp rainfall_sum humid `controls' if inlist(income_classification_1st,"H","UM"), absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m2	
reghdfe poor685 temp rainfall_sum humid `controls' if inlist(income_classification_1st,"L","LM"), absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m3
reghdfe poor685 temp rainfall_sum humid `controls' if inlist(income_classification_1st,"H","UM"), absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m4
reghdfe theil temp rainfall_sum humid `controls' if inlist(income_classification_1st,"L","LM"), absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m5
reghdfe theil temp rainfall_sum humid `controls' if inlist(income_classification_1st,"H","UM"), absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m6
	
local opts ///
	cells(b(star fmt(3)) se(par fmt(3))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2, fmt(0 3) ///
	label("Observations" "R-squared")) ///	
	eqlabels(none) mtitle("poor365 - low inc" "poor365 - high inc" "poor685 - low inc" "poor685 - high inc" "theil - low inc" "theil - high inc") ///
	collabels(,none) varlabels(temp "Temperature" rainfall_ave "Rainfall" humid "Humidity") varwidth(25) ///
	title("Table S15 - FE")
	
esttab m*, `opts'
esttab m* using "${date}/_tables/_tab_s15_FE.csv", replace `opts'

	
* LD model 
bysort 	geo_code2_new (year): egen year_min = min(year)
bysort 	geo_code2_new (year): egen year_max = max(year)

keep if year == year_min | year == year_max

bysort geo_code2_new (year): gen n = _n
bysort geo_code2_new (year): gen N = _N
	keep if N==2
	
encode geo_code2_new, gen(id_region)	
xtset id_region n
foreach v in gini theil temp poor215 poor365 poor685 rainfall_sum humid ln_GDPppp Unempilo agri manuf popgr  {
	gen `v'_d = D.`v'
}
	
collapse (mean) poor215_d poor365_d poor685_d gini_d theil_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d, by(geo_code2_new year income_classification_1st)
	
estimates clear	

local controls ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d   

reg poor365_d temp_d rainfall_sum_d humid_d `controls' if inlist(income_classification_1st,"L","LM"), cluster(geo_code2_new) 
	est store m1	
reg poor365_d temp_d rainfall_sum_d humid_d `controls' if inlist(income_classification_1st,"H","UM"), cluster(geo_code2_new) 	
	est store m2
reg poor685_d temp_d rainfall_sum_d humid_d `controls' if inlist(income_classification_1st,"L","LM"), cluster(geo_code2_new) 
	est store m3
reg poor685_d temp_d rainfall_sum_d humid_d `controls' if inlist(income_classification_1st,"H","UM"), cluster(geo_code2_new) 	
	est store m4
reg theil_d temp_d rainfall_sum_d humid_d `controls' if inlist(income_classification_1st,"L","LM"), cluster(geo_code2_new) 
	est store m5
reg theil_d temp_d rainfall_sum_d humid_d `controls' if inlist(income_classification_1st,"H","UM"), cluster(geo_code2_new) 
	est store m6
	
local opts ///
	cells(b(star fmt(3)) se(par fmt(3))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2, fmt(0 3) ///
	label("Observations" "R-squared")) ///	
	eqlabels(none) mtitle("poor365 - low inc" "poor365 - high inc" "poor685 - low inc" "poor685 - high inc" "theil - low inc" "theil - high inc") ///
	collabels(,none) varlabels(temp "Temperature" rainfall_ave "Rainfall" humid "Humidity") varwidth(25) ///
	title("Table S15 - LD")	
	
esttab m*, `opts'
esttab m* using "${date}/_tables/_tab_s15_LD.csv", replace `opts'

	
//==========================//	
	
// T-test: Lower income vs Higher income
* Fixed effects model
use "${date}/_data/spid_for_analysis_v2.dta", clear

encode geo_code2_new, gen(id_region)

	sort code year
	merge m:1 code year using "${date}/_data/income_classification.dta"
	drop if _merge==2
	drop _merge

* Income classification based on 1st data point
bysort code (year): gen income_classification_1st = income_classification[1]
	
local controls ln_GDPppp Unempilo agri manuf popgr 
	
estimates clear	
qui reg poor365 temp rainfall_sum humid b2010.year b42.id_region `controls' if inlist(income_classification_1st,"L","LM")	
	est store low_inc
qui reg poor365 temp rainfall_sum humid b2010.year b42.id_region `controls' if inlist(income_classification_1st,"H","UM")
	est store high_inc
	
qui suest low_inc high_inc	
test [low_inc_mean]temp - [high_inc_mean]temp = 0
	
estimates clear	
qui reg poor685 temp rainfall_sum humid b2010.year b42.id_region `controls' if inlist(income_classification_1st,"L","LM")	
	est store low_inc
qui reg poor685 temp rainfall_sum humid b2010.year b42.id_region `controls' if inlist(income_classification_1st,"H","UM")
	est store high_inc
	
qui suest low_inc high_inc	
test [low_inc_mean]temp - [high_inc_mean]temp = 0

estimates clear
qui reg theil temp rainfall_sum humid b2010.year b42.id_region `controls' if inlist(income_classification_1st,"L","LM")
	est store low_inc
qui reg theil temp rainfall_sum humid b2010.year b42.id_region `controls' if inlist(income_classification_1st,"H","UM")
	est store high_inc
	
qui suest low_inc high_inc	
test [low_inc_mean]temp - [high_inc_mean]temp = 0

* LD model
use "${date}/_data/spid_for_analysis_v2.dta", clear

	sort code year
	merge m:1 code year using "${date}/_data/income_classification.dta"
	drop if _merge==2
	drop _merge

* Income classification based on 1st data point
bysort code (year): gen income_classification_1st = income_classification[1]
	
bysort 	geo_code2_new (year): egen year_min = min(year)
bysort 	geo_code2_new (year): egen year_max = max(year)

keep if year == year_min | year == year_max

bysort geo_code2_new (year): gen n = _n
bysort geo_code2_new (year): gen N = _N
	keep if N==2
	
encode geo_code2_new, gen(id_region)	
xtset id_region n
foreach v in gini theil temp poor215 poor365 poor685 rainfall_sum humid ln_GDPppp Unempilo agri manuf popgr {
	gen `v'_d = D.`v'
}
	
local controls ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d   
	
estimates clear	
qui reg poor365_d temp_d rainfall_sum_d humid_d `controls' if inlist(income_classification_1st,"L","LM")
	est store low_inc
qui reg poor365_d temp_d rainfall_sum_d humid_d `controls' if inlist(income_classification_1st,"H","UM")
	est store high_inc	
	
qui suest low_inc high_inc	
test [low_inc_mean]temp_d - [high_inc_mean]temp_d = 0
	
estimates clear	
qui reg poor685_d temp_d rainfall_sum_d humid_d `controls' if inlist(income_classification_1st,"L","LM")
	est store low_inc
qui reg poor685_d temp_d rainfall_sum_d humid_d `controls' if inlist(income_classification_1st,"H","UM")
	est store high_inc	
	
qui suest low_inc high_inc	
test [low_inc_mean]temp_d - [high_inc_mean]temp_d = 0

estimates clear	
qui reg theil_d temp_d rainfall_sum_d humid_d `controls' if inlist(income_classification_1st,"L","LM")
	est store low_inc
qui reg theil_d temp_d rainfall_sum_d humid_d `controls' if inlist(income_classification_1st,"H","UM")
	est store high_inc	
	
qui suest low_inc high_inc	
test [low_inc_mean]temp_d - [high_inc_mean]temp_d = 0

// T-test: FE vs LD
use "${date}/_data/spid_for_analysis_v2.dta", clear

encode geo_code2_new, gen(id_region)

	sort code year
	merge m:1 code year using "${date}/_data/income_classification.dta"
	drop if _merge==2
	drop _merge

* Income classification based on 1st data point
bysort code (year): gen income_classification_1st = income_classification[1]
		
qui reg poor365 temp rainfall_sum humid i.id_region i.year ln_GDPppp Unempilo agri manuf popgr if inlist(income_classification_1st,"L","LM")
	est store fe_poor365_lowinc	
qui reg poor685 temp rainfall_sum humid i.id_region i.year ln_GDPppp Unempilo agri manuf popgr if inlist(income_classification_1st,"L","LM")
	est store fe_poor685_lowinc
qui reg theil temp rainfall_sum humid i.id_region i.year ln_GDPppp Unempilo agri manuf popgr if inlist(income_classification_1st,"L","LM")
	est store fe_theil_lowinc
	
qui reg poor365 temp rainfall_sum humid i.id_region i.year ln_GDPppp Unempilo agri manuf popgr if inlist(income_classification_1st,"H","UM")
	est store fe_poor365_highinc	
qui reg poor685 temp rainfall_sum humid i.id_region i.year ln_GDPppp Unempilo agri manuf popgr if inlist(income_classification_1st,"H","UM")
	est store fe_poor685_highinc
qui reg theil temp rainfall_sum humid i.id_region i.year ln_GDPppp Unempilo agri manuf popgr if inlist(income_classification_1st,"H","UM")
	est store fe_theil_highinc
	
bysort 	geo_code2_new (year): egen year_min = min(year)
bysort 	geo_code2_new (year): egen year_max = max(year)

keep if year == year_min | year == year_max

bysort geo_code2_new (year): gen n = _n
bysort geo_code2_new (year): gen N = _N
	keep if N==2
	
xtset id_region n
foreach v in gini theil temp poor215 poor365 poor685 rainfall_sum humid ln_GDPppp Unempilo agri manuf popgr {
	gen `v'_d = D.`v'
}
	
qui reg poor365_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d  if inlist(income_classification_1st,"L","LM")
	est store ld_poor365_lowinc		
qui reg poor685_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d  if inlist(income_classification_1st,"L","LM")
	est store ld_poor685_lowinc	
qui reg theil_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d  if inlist(income_classification_1st,"L","LM")
	est store ld_theil_lowinc	
	
qui reg poor365_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d  if inlist(income_classification_1st,"H","UM")
	est store ld_poor365_highinc	
qui reg poor685_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d  if inlist(income_classification_1st,"H","UM")
	est store ld_poor685_highinc	
qui reg theil_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d  if inlist(income_classification_1st,"H","UM")
	est store ld_theil_highinc	
	
qui suest fe_poor365_lowinc ld_poor365_lowinc	
test [fe_poor365_lowinc_mean]temp - [ld_poor365_lowinc_mean]temp_d = 0
qui suest fe_poor685_lowinc ld_poor685_lowinc	
test [fe_poor685_lowinc_mean]temp - [ld_poor685_lowinc_mean]temp_d = 0
qui suest fe_theil_lowinc ld_theil_lowinc
test [fe_theil_lowinc_mean]temp - [ld_theil_lowinc_mean]temp_d = 0

qui suest fe_poor365_highinc ld_poor365_highinc	
test [fe_poor365_highinc_mean]temp - [ld_poor365_highinc_mean]temp_d = 0
qui suest fe_poor685_highinc ld_poor685_highinc	
test [fe_poor685_highinc_mean]temp - [ld_poor685_highinc_mean]temp_d = 0
qui suest fe_theil_highinc ld_theil_highinc
test [fe_theil_highinc_mean]temp - [ld_theil_highinc_mean]temp_d = 0
